
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import Unicode

from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker

from zope.sqlalchemy import ZopeTransactionExtension

from sqlalchemy import Text


from sqlalchemy import Table, Column, Integer, ForeignKey
from sqlalchemy.orm import relationship, backref



from scp.modelo.models import Base


association_table = Table('usuario_rol', Base.metadata,
    Column('usuario_id', Integer, ForeignKey('usuario.id')),
    Column('rol_id', Integer, ForeignKey('rol.id'))
)


class Usuario(Base):
    """ The SQLAlchemy declarative model class for a Page object. """
    __tablename__ = 'usuario'
    id = Column(Integer, primary_key=True)
    username = Column(Unicode(20), nullable=False, unique=True)
    nombre = Column(Unicode(100), nullable=False)
    password = Column(Unicode(20), nullable=False)
    roles = relationship("Rol",
                    secondary=association_table)
